import random

import redis
import requests


def save_request_url(url):
    client = redis.Redis(host='localhost', port=6379, db=0)
    client.lpush("requested_url", url)
    client.close()


def is_requested_url(url):
    client = redis.Redis(host='localhost', port=6379, db=0)
    urls = client.lrange("requested_url",0, -1)

    client.close()
    print(url.encode() in urls)
    return url.encode() in urls

urls = [f'https://httpbin.org/get?age={random.randint(1,50)}' for i in range(100)]

urls = set(urls)
print(len(urls))
for url in urls:
    if not is_requested_url(url):
        response = requests.get(url)
        print(response.status_code)
        save_request_url(url)
    else:
        print("已经请求过了")